Skip to content

fix(particlesys): Add or simplify null-checks to createParticleSystem calls#2724

Open
stephanmeesters wants to merge 4 commits into
TheSuperHackers:mainfrom
stephanmeesters:fix/createparticlesystem-nullcheck
Open

fix(particlesys): Add or simplify null-checks to createParticleSystem calls#2724
stephanmeesters wants to merge 4 commits into
TheSuperHackers:mainfrom
stephanmeesters:fix/createparticlesystem-nullcheck

Conversation

@stephanmeesters
Copy link
Copy Markdown

@stephanmeesters stephanmeesters commented May 17, 2026

  • Ensure that the result of createParticleSystem is null checked
  • Remove unnecessary particle template checks when straightforward to do so

Todo

  • Replicate in Generals

@stephanmeesters stephanmeesters marked this pull request as ready for review May 17, 2026 11:14
@stephanmeesters stephanmeesters changed the title fix(particlesys): Add or optimize null-checks to createParticleSystem calls refactor(particlesys): Add or optimize null-checks to createParticleSystem calls May 17, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR simplifies null-checking patterns around createParticleSystem calls across 22 files. The refactoring is sound: ParticleSystemManager::createParticleSystem already guards against a null template argument and returns nullptr immediately, so removing the pre-call template null-checks and checking only the returned pointer is functionally equivalent.

  • Core pattern change (all files): if (tmpl) { sys = create(tmpl); if (sys) { ... } } is collapsed to sys = create(tmpl); if (sys) { ... }, removing one level of nesting throughout.
  • ParticleSys.cpp: Additionally removes the null guard in createSlaveSystem (safe — handled by createParticleSystem itself) and hoists the createParticleSystem call before the template check in update().
  • ChinookAIUpdate.cpp: Introduces a minor mixed tab/space indentation inconsistency in the replacement block.

Confidence Score: 5/5

Safe to merge — all call sites behave identically before and after the change because createParticleSystem returns nullptr for a null template.

The refactoring is purely mechanical: every removed template guard is already replicated inside createParticleSystem itself, so no code path produces a different outcome. The only notable issue is a small indentation inconsistency in ChinookAIUpdate.cpp.

BeaconClientUpdate.cpp has an open discussion with a requested revert tracked in the existing thread; ChinookAIUpdate.cpp has a minor indentation inconsistency.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/System/ParticleSys.cpp Simplifies two call sites: moves createParticleSystem call before the null-template guard in update(), and removes the null-template guard entirely in createSlaveSystem(). Both are safe — the function already returns nullptr for a null template argument.
Core/GameEngine/Source/GameClient/Drawable/Update/BeaconClientUpdate.cpp Collapses the double-null-check around the failsafe path; technically safe since createParticleSystem handles nullptr, but this specific change has an ongoing discussion in the thread and a senior developer has requested a revert.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/ChinookAIUpdate.cpp Removes the template null-guard correctly, but introduces mixed tab/space indentation on the if(system) block, breaking consistency with surrounding code.
Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp Removes the parentTemp null-guard before createParticleSystem; safe because createParticleSystem returns nullptr for a null template, preserving the original skip-if-not-found behaviour.
GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp Same simplification as Generals/ScriptEngine.cpp — null-template guard removed, createParticleSystem handles nullptr safely.
Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp Removes both the outer m_IRGridParticleSysTmpl guard and the inner redundant check, collapsing to a single createParticleSystem + null result check. Functionally equivalent.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp Keeps the outer m_IRGridParticleSysTmpl guard (unlike the Generals counterpart) and removes only the inner redundant check. Functionally identical; minor stylistic inconsistency between the two codebases.
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp Separates the template lookup and creation calls, guarding only on the system result. Correct and safe.
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cpp Same pattern as W3DTankTruckDraw — template lookup and system creation separated, null-check on system result only. Clean.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph Before ["Before (old pattern)"]
        A[findTemplate name] --> B{template != nullptr?}
        B -- No --> Z[Skip]
        B -- Yes --> C[createParticleSystem template]
        C --> D{system != nullptr?}
        D -- No --> Z
        D -- Yes --> E[Use system]
    end
    subgraph After ["After (new pattern)"]
        A2[findTemplate name] --> C2[createParticleSystem template]
        C2 --> D2{system != nullptr?}
        D2 -- No --> Z2[Skip]
        D2 -- Yes --> E2[Use system]
    end
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/ChinookAIUpdate.cpp:1202-1206
Indentation inconsistency introduced — the `if( system )` block now uses a different tab/space mix than the `tmp` and `system` declarations directly above it. The declaration lines use one tab + six spaces, while the `if` body uses two tabs + two spaces. This breaks the visual alignment present in the surrounding code and the original indentation style.

```suggestion
	      ParticleSystem *system = TheParticleSystemManager->createParticleSystem( tmp );
	      if( system )
	      {
		      system->setPosition( &pos );
	      }
```

Reviews (4): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile

Comment thread Core/GameEngine/Source/GameClient/Drawable/Update/BeaconClientUpdate.cpp Outdated
@xezon xezon changed the title refactor(particlesys): Add or optimize null-checks to createParticleSystem calls fix(particlesys): Add or simplify null-checks to createParticleSystem calls May 18, 2026
@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing Fix Is fixing something, but is not user facing labels May 18, 2026
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

@stephanmeesters
Copy link
Copy Markdown
Author

Replicated: ChinookAIUpdate.cpp and EMPUpdate.cpp don't exist in Generals, LaserUpdate.cpp and StealthDetectorUpdate.cpp diverge a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants